package com.galaxy.device.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.galaxy.common.core.domain.R;
import com.galaxy.common.core.validate.AddGroup;
import com.galaxy.common.core.validate.EditGroup;
import com.galaxy.common.log.annotation.Log;
import com.galaxy.common.log.enums.BusinessType;
import com.galaxy.common.mybatis.core.page.PageQuery;
import com.galaxy.common.mybatis.core.page.TableDataInfo;
import com.galaxy.device.domain.bo.DeviceMachineTypeBo;
import com.galaxy.device.domain.vo.DeviceMachineTypeVo;
import com.galaxy.device.service.IDeviceMachineTypeService;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 机器类型Controller
 */
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/machineType")
public class DeviceMachineTypeController {

    private final IDeviceMachineTypeService machineTypeService;

    /**
     * 查询机器类型列表
     */
    @GetMapping("/list")
    @SaCheckPermission("device:machineType:list")
    public TableDataInfo<DeviceMachineTypeVo> list(DeviceMachineTypeBo bo, PageQuery pageQuery) {
        return machineTypeService.queryPageList(bo, pageQuery);
    }

    /**
     * 获取机器类型详细信息
     */
    @GetMapping("/{id}")
    @SaCheckPermission("device:machineType:list")
    public R<DeviceMachineTypeVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long id) {
        return R.ok(machineTypeService.getInfo(id));
    }

    /**
     * 新增机器类型
     */
    @Log(title = "机器类型", businessType = BusinessType.INSERT)
    @PostMapping
    @SaCheckPermission("device:machineType:add")
    public R<Void> add(@Validated(AddGroup.class) @RequestBody DeviceMachineTypeBo bo) {
        machineTypeService.add(bo);
        return R.ok();
    }

    /**
     * 修改机器类型
     */
    @Log(title = "机器类型", businessType = BusinessType.UPDATE)
    @PutMapping
    @SaCheckPermission("device:machineType:update")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody DeviceMachineTypeBo bo) {
        machineTypeService.update(bo);
        return R.ok();
    }

    /**
     * 删除机器类型
     */
    @Log(title = "机器类型", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @SaCheckPermission("device:machineType:delete")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] ids) {
        machineTypeService.deleteBatch(ids);
        return R.ok();
    }
}
